from typing import List, Tuple, Dict

N = int(input())
M = [None for _ in range(N)]
for i in range(N):
    M[i] = list(map(int, input().split()))


class Picture:
    def __init__(self, i) -> None:
        self.index = i
        self.friends = []

types = set()
pictures:List[Picture] = [None]*N
for i in range(N):
    pic = Picture(i)
    pictures[i] = pic
    
    for j in range(i):
        if M[i][j] > 0:
            types.discard(j)
            pictures[i].friends.append(pictures[j])
            pictures[j].friends.append(pictures[i])
            
    types.add(i)

def cal(root:Picture, picList:List[Picture]):
    ans = 0
    for f in root.friends:
        if f not in picList:
            ans += M[root.index][f.index]
    picList.append(root)
    for f in root.friends:
        if f not in picList:
            ans += cal(f, picList)
    return ans

ans = []
for i in types:
    ans.append(cal(pictures[i],[]))

ans.sort()
print(ans[::-1])